<template>
	<view class="">
		<bg-video></bg-video>
	</view>
</template>

<script>
	export default {
		data: function() {
			return {
				sp: false,
				scrollTop: 0,
				CustomBar: this.CustomBar,
				StatusBar: this.StatusBar,
				fromid: "",
				md: {}
			};
		},
		computed: {},
		onLoad: function(option) {

			if (option.clientid) {
				this.fromid = option.clientid;
			}
			// return;
			this.autorLogin();
			
		},
		methods: {
			adChange: function(md) {
				this.md.pcode = md.pcode;
				this.md.scode = md.scode;
				this.md.qcode = md.qcode;
				this.md.address = md.address;
				this.sp = false;
			},
			toIndex: function() {
				
				uni.navigateTo({
					url: "/pages/index"
				});
				// uni.navigateTo({
				// 	url: "/pages/cmdjl/md/mdxx"
				// });
			},
			autorLogin: function() {
				uni.login({
					success: res => {
						this.ht.login(res.code, this.fromid).then(this.findout).then(this.toIndex).catch(err => {
							this.toIndex();
						});
					}
				});
			},
			findout: function() {
				return this.location.loadLocation().then(data => {
					this.parseCity(data.latitude, data.longitude);
				});
			},
			parseCity: function(wd, jd) {
				this.location.jwdToLocation(wd, jd).then(res => {
					if (res.ad_info.nation_code != 156) {
						this.message.error("当前定位不在中国");
						return;
					}

					try {
						let qcode = res.ad_info.adcode;
						let scode = this.location.localmap.cmap[qcode].scode;
						let pcode = this.location.localmap.cmap[scode].scode;



						const currentObj = this.location.localmap.cmap[scode];
						let curLocation = {};
						if (currentObj) {
							if (currentObj.scode === "000000") {
								curLocation.proviceid = currentObj.cricode;
								curLocation.provice = this.location.localmap.cmap[curLocation.proviceid];
							} else {
								curLocation.cityid = currentObj.cricode;
								curLocation.city = this.location.localmap.cmap[curLocation.cityid];

								curLocation.proviceid = curLocation.city.scode;
								curLocation.provice = this.location.localmap.cmap[curLocation.proviceid];
							}

							this.store.commit("setLocation", curLocation);

							this.store.commit("setPosition", {
								jd: jd,
								wd: wd
							});
						}

					} catch (err) {
						this.message.error("定位出现问题");
						return;
					}

				});
			}
		}
	}
</script>

<style>
</style>